package com.ruoyi.web.controller.business;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserSalary;
import com.ruoyi.system.service.ISysUserSalaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户薪资计算Controller
 *
 * @author ruoyi
 * @date 2023-06-26
 */
@Controller
@RequestMapping("/system/salary")
public class SysUserSalaryController extends BaseController {
    private String prefix = "system/salary";

    @Autowired
    private ISysUserSalaryService sysUserSalaryService;

    @RequiresPermissions("system:salary:view")
    @GetMapping()
    public String salary() {
        return prefix + "/salary";
    }

    /**
     * 查询用户薪资计算列表
     */
    @RequiresPermissions("system:salary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUserSalary sysUserSalary) {
        startPage();
        List<SysUserSalary> list = sysUserSalaryService.selectSysUserSalaryList(sysUserSalary);
        return getDataTable(list);
    }

    /**
     * 导出用户薪资计算列表
     */
    @RequiresPermissions("system:salary:export")
    @Log(title = "用户薪资计算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysUserSalary sysUserSalary) {
        List<SysUserSalary> list = sysUserSalaryService.selectSysUserSalaryList(sysUserSalary);
        ExcelUtil<SysUserSalary> util = new ExcelUtil<SysUserSalary>(SysUserSalary.class);
        return util.exportExcel(list, "用户薪资计算数据");
    }

    /**
     * 新增用户薪资计算
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户薪资计算
     */
    @RequiresPermissions("system:salary:add")
    @Log(title = "用户薪资计算", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysUserSalary sysUserSalary) {
        sysUserSalary.setUpdateTime(new Date());
        return toAjax(sysUserSalaryService.insertSysUserSalary(sysUserSalary));
    }

    /**
     * 修改用户薪资计算
     */
    @RequiresPermissions("system:salary:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap) {
        SysUserSalary sysUserSalary = sysUserSalaryService.selectSysUserSalaryByUserId(userId);
        mmap.put("sysUserSalary", sysUserSalary);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户薪资计算
     */
    @RequiresPermissions("system:salary:edit")
    @Log(title = "用户薪资计算", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysUserSalary sysUserSalary) {
        return toAjax(sysUserSalaryService.updateSysUserSalary(sysUserSalary));
    }

    /**
     * 删除用户薪资计算
     */
    @RequiresPermissions("system:salary:remove")
    @Log(title = "用户薪资计算", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysUserSalaryService.deleteSysUserSalaryByUserIds(ids));
    }


    /**
     * 获取单条数据
     */
    @RequiresPermissions("system:salary:add")
    @Log(title = "获取单条数据", businessType = BusinessType.INSERT)
    @PostMapping("/getbyid/{userid}")
    @ResponseBody
    public AjaxResult getbyid(@PathVariable("userid") Long userid) {
        return success(sysUserSalaryService.selectSysUserSalaryByUserId(userid));
    }
}
